package com.udian.frame;

import java.nio.charset.Charset;

import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

@Configuration
public class UdianHttpMessageConverters {
	
	 @Bean
	 public HttpMessageConverters customConverters() {
		 //设置返回消息为utf-8编码
		 StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(Charset.forName("UTF-8"));
		 
		 //设置返回消息为JSON格式，对象转json采用Jackson组件
		 MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
		 jsonConverter.setPrettyPrint(true);
		 
		 return new HttpMessageConverters(stringConverter,jsonConverter);
	 }
	 
}
